<?php
/**
 * Front controller script.
 * Your site bootstrap file (usually index.php) shoud only include this file, so all requests 
 * will go through this script. It includes main PSA files, opens session, sets data about plugins,
 * instances main objects and calls router plugin.
 * 
 * LICENSE:
 * 
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with This library. If not, see <{@link http://www.gnu.org/licenses/}>.
 *
 * @link http://code.google.com/p/phpstartapp/
 * @author Bojan Mauser <bmauser@gmail.com>
 * @copyright Bojan Mauser 2009
 * @package psa
 * @version $Id: front_controller.php 464 2009-03-24 00:30:12Z bmauser $
 */


// find out PSA main directory
$PSA_CFG['folders']['basedir'] = dirname(__FILE__);


// include PSA config file
include_once $PSA_CFG['folders']['basedir'] . '/config.php' ;


// Error reporting. Enable or disable this through $PSA_CFG['develop_mode'] configuration option
if($PSA_CFG['develop_mode']){
	error_reporting(E_ALL);
	ini_set("display_errors",1);
}
else{
	ini_set("display_errors",0);
}


// include required files
include_once $PSA_CFG['folders']['basedir'] . '/scripts/functions.php';
include_once $PSA_CFG['folders']['basedir'] . '/scripts/Psa_Singleton.class.php';
include_once $PSA_CFG['folders']['basedir'] . '/scripts/Psa_Pdo.class.php';
include_once $PSA_CFG['folders']['basedir'] . '/scripts/Psa_User.class.php';
include_once $PSA_CFG['folders']['basedir'] . '/scripts/Psa_Group.class.php';
include_once $PSA_CFG['folders']['basedir'] . '/scripts/Psa_Logger.class.php';
include_once $PSA_CFG['folders']['basedir'] . '/scripts/Psa_Plugin.class.php';
include_once $PSA_CFG['folders']['basedir'] . '/scripts/Psa_Registry.class.php';
include_once $PSA_CFG['folders']['basedir'] . '/scripts/Psa_Result.class.php';
include_once $PSA_CFG['folders']['basedir'] . '/scripts/Psa_Validator.class.php';


// database connection wrapper object
$psa_database = new Psa_Pdo();


// profile log object. If profile log is enabled
if($PSA_CFG['profile_log']){
	include_once($PSA_CFG['folders']['basedir'] . '/scripts/Psa_Profile_Logger.class.php');
}


// register plugins on every request if develop mode is on
if($PSA_CFG['develop_mode']){
	Psa_Plugin::get_instance()->save();
	
	// collect informations about request
	Psa_Registry::get_instance()->psa_request_info['globals'] = $GLOBALS;
}


// register psa_autoload() function as __autoload() implementation
spl_autoload_register('psa_autoload');


// call Router
psa_run_plugins(array('Router' => array('psa_main' => array())));

